#include "virtural_camera.h"
#include <cmath>

VIRTURAL_CAMERA::VIRTURAL_CAMERA()
{
    height=CAMERAHEIGHT;
    width=CAMERAWIDTH;
    scanImage=new QColor[CAMERAHEIGHT*CAMERAWIDTH];
    cameraX=100;
    cameraY=100;
    cameraTheata=0;
}

VIRTURAL_CAMERA::~VIRTURAL_CAMERA()
{
    delete [] scanImage;
}

void VIRTURAL_CAMERA::GetPos(double x, double y, double theata)
{
    cameraX=x;
    cameraY=y;
    cameraTheata=theata;
}

void VIRTURAL_CAMERA::ScanMap(QImage *map)
{
    int count=0;
    for(int i=0;i<height;++i) //y方向取10个坐标[0，9]
    {
        for(int j=0;j<width;++j) //x方向取21个坐标[-10,10]
        {
            int pixelPointX=cameraX+(j-width/2)*cos(cameraTheata)+i*sin(cameraTheata);
            int pixelPointY=cameraY-(j-width/2)*sin(cameraTheata)+i*cos(cameraTheata);
            scanImage[count++]=map->pixel(pixelPointX,pixelPointY);
        }
    }
}
